
package CelestialWeb;

import CelestialDataStructures.ForEachMapDelegate;
import java.io.PrintWriter;

public class WriteXMLError<K extends Integer, V extends String> extends ForEachMapDelegate<K, V>{

    private PrintWriter m_pw;
    /*************************************************************************/
    public void setPrintWriter(PrintWriter pw){ this.m_pw = pw; }
    /*************************************************************************/
    /* implements ForEachMapDelegate */
    protected @Override void beforeForEach(){ m_pw.println("<Errors>"); }
    /*************************************************************************/
    protected @Override void afterForEach(){
        m_pw.println("</Errors>");
        m_pw.close();
    }
    /*************************************************************************/
    protected @Override void forEach(Integer code, String msg){

        m_pw.println("<Error>");
        m_pw.println("<ErrorCode>" + code + "</ErrorCode>");
        m_pw.println("<ErrorMessage>" + msg + "</ErrorMessage>");
        m_pw.println("</Error>");
    }
    /*************************************************************************/
    /* Client methods */
    public void writeSingleError(int code, String msg, PrintWriter pw){
        pw.println("<Errors><Error>");
        pw.println("<ErrorCode>" + code + "</ErrorCode>");
        pw.println("<ErrorMessage>" + msg + "</ErrorMessage>");
        pw.println("</Error></Errors>");
        pw.close();
    }
    /*************************************************************************/
    public void WriteError(int code, String msg){
        java.lang.Integer i = new java.lang.Integer(code);
        forEach(i, msg);
    }
}
